package org.radsimplified.genapp.metadata;

import java.util.ArrayList;
import java.util.List;

public class App {

	protected static App app;
	
	public static App getApp() {
		return app;
	}
	
	public static void setApp(App app) {
		App.app = app;
	}

	protected String name;
    protected String appId;
    protected String groupId;
    protected String artifactId;
    protected String db;
    protected String dbUser;
    protected String dbPassword;
    protected String emailHost;
    protected String emailId;
    protected String emailPassword;
    protected Boolean restricted = true;
    protected Byte pageSize;
    protected String datePattern = "yyyy-MM-dd";
    protected String dateTimePattern = "yyyy-MM-dd HH:mm";
    protected String timePattern = "HH:mm";
    protected Integer maxUploadSize;
    protected List<Property> properties = new ArrayList<Property>();
    protected List<Message> messages = new ArrayList<Message>();
    protected List<BizEntity> entities = new ArrayList<BizEntity>();
    protected List<String> modules = new ArrayList<String>();
    
    public void setName(String name) {
		this.name = name != null && name.equals("") ? null : name;
    }

	public String getName() {
		return name;
	}

    public void setAppId(String appId) {
		this.appId = appId != null && appId.equals("") ? null : appId;
    }

	public String getAppId() {
		return appId;
	}

    public void setGroupId(String groupId) {
		this.groupId = groupId != null && groupId.equals("") ? null : groupId;
    }

	public String getGroupId() {
		return groupId;
	}

    public void setArtifactId(String artifactId) {
		this.artifactId = artifactId != null && artifactId.equals("") ? null : artifactId;
    }

	public String getArtifactId() {
		return artifactId;
	}

    public String getDb() {
		return db;
	}

	public void setDb(String db) {
		this.db = db;
	}

	public void setDbUser(String dbUser) {
		this.dbUser = dbUser != null && dbUser.equals("") ? null : dbUser;
    }

	public String getDbUser() {
		return dbUser;
	}

    public void setDbPassword(String dbPassword) {
		this.dbPassword = dbPassword != null && dbPassword.equals("") ? null : dbPassword;
    }

	public String getDbPassword() {
		return dbPassword;
	}

    public void setEmailHost(String emailHost) {
		this.emailHost = emailHost != null && emailHost.equals("") ? null : emailHost;
    }

	public String getEmailHost() {
		return emailHost;
	}

    public void setEmailId(String emailId) {
		this.emailId = emailId != null && emailId.equals("") ? null : emailId;
    }

	public String getEmailId() {
		return emailId;
	}

    public void setEmailPassword(String emailPassword) {
		this.emailPassword = emailPassword != null && emailPassword.equals("") ? null : emailPassword;
    }

	public String getEmailPassword() {
		return emailPassword;
	}

    public void setRestricted(Boolean restricted) {
		this.restricted = restricted;
    }

	public Boolean getRestricted() {
		return restricted;
	}

    public void setPageSize(Byte pageSize) {
		this.pageSize = pageSize;
    }

	public Byte getPageSize() {
		return pageSize;
	}

    public void setDatePattern(String datePattern) {
		this.datePattern = datePattern != null && datePattern.equals("") ? null : datePattern;
    }

	public String getDatePattern() {
		return datePattern;
	}

    public void setDateTimePattern(String dateTimePattern) {
		this.dateTimePattern = dateTimePattern != null && dateTimePattern.equals("") ? null : dateTimePattern;
    }

	public String getDateTimePattern() {
		return dateTimePattern;
	}

    public void setTimePattern(String timePattern) {
		this.timePattern = timePattern != null && timePattern.equals("") ? null : timePattern;
    }

	public String getTimePattern() {
		return timePattern;
	}

    public void setMaxUploadSize(Integer maxUploadSize) {
		this.maxUploadSize = maxUploadSize;
    }

	public Integer getMaxUploadSize() {
		return maxUploadSize;
	}

    public void addMessage(Message obj) {
    	messages.add(obj);
    }
    
	public List<Message> getMessages() {
		return messages;
	}

	public BizEntity getEntity(String entityName) {
		
		for (BizEntity entity: entities)
			if (entity.getName().equals(entityName))
				return entity;
		return null;
	}

	public void addProperty(Property property) {
		properties.add(property);
	}

	public void addEntity(BizEntity entity) {
		entities.add(entity);
	}

	public List<Property> getProperties() {
		return properties;
	}

	public List<BizEntity> getEntities() {
		return entities;
	}

	public List<String> getModules() {
		return modules;
	}
	
	public void addModule(String module) {
		for (String m: modules)
			if (m.equals(module))
				return;
		modules.add(module);
	}
	
}
